package com.sphd.Restaurant.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;

import com.sphd.Restaurant.R;
import com.sphd.Restaurant.adapters.MyViewPagerAdapter;
import com.sphd.Restaurant.base.BaseActivity;
import com.sphd.Restaurant.fragments.msgsFragments.DiscountMsgFragment;
import com.sphd.Restaurant.fragments.msgsFragments.SystemMsgFragment;
import com.sphd.Restaurant.utils.AppManager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MyMsgActivity extends BaseActivity {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tabs)
    TabLayout tabs;
    @BindView(R.id.vp_msg)
    ViewPager vpMsg;
    MyViewPagerAdapter myViewPagerAdapter;
    SystemMsgFragment systemMsgFragment;
    DiscountMsgFragment discountMsgFragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_msg);
        AppManager.getAppManager().addActivity(this);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        setToolBar(toolbar,"消息中心",true);
        toolbar.setNavigationOnClickListener(view -> AppManager.getAppManager().finishActivity(this));
        systemMsgFragment=new  SystemMsgFragment();
        discountMsgFragment=new  DiscountMsgFragment();
        List<Fragment> fragments =new ArrayList<>();
        fragments.add(systemMsgFragment);
        fragments.add(discountMsgFragment);
        String[] titles={"系统消息","优惠信息"};
        myViewPagerAdapter=new MyViewPagerAdapter(getSupportFragmentManager(), fragments,titles);
        vpMsg.setAdapter(myViewPagerAdapter);
        tabs.setupWithViewPager(vpMsg);
    }

}
